package server;

import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;

import model.*;
import controller.Controller;
import view.View;
import gui.AccountForm;
import gui.AccountStruct;
import gui.CodeBehind;
import gui.Form;
import gui.InputForm;

public class Main {
	public static void main(String args[]){
		Form form = new Form("Mini SQL Server");
		InputForm input = new InputForm();
		AccountForm af = new AccountForm();
		CodeBehind.f = form;		
		CodeBehind.input = input;
		List<AccountStruct> accounts = new ArrayList<AccountStruct>();
		CodeBehind.accountList = accounts;
		CodeBehind.af = af;
		/*
		 * 
		 */
		Controller c = new Controller();		
		Model model = new Model();					
		model.loadDatabase();
		/*
		 * 
		 */
		try {
			ServerSocket ss = new ServerSocket(18119);
			System.out.println(InetAddress.getLocalHost());
			ConnectThread ct = new ConnectThread(ss, model, accounts);			
			ct.start();
		}
		catch (Exception e) {
			// TODO: handle exception
		}
					
		c.set_model(model);
		View v = new View(c, model, form);
		model.addObserver(v);
		CodeBehind.view = v;
		CodeBehind.initialize();
		form.setVisible(true);		
	}
}
